package com.sweetcircle.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sweetcircle.domain.dto.MessageSendDto;
import com.sweetcircle.domain.dto.TokenUserInfoDto;
import com.sweetcircle.domain.enums.PageSize;
import com.sweetcircle.domain.po.ChatMessage;
import com.sweetcircle.domain.po.UserInfo;
import com.sweetcircle.domain.query.ChatMessageQuery;
import com.sweetcircle.domain.query.SimplePage;
import com.sweetcircle.domain.vo.PaginationResultVO;
import com.sweetcircle.mapper.ChatMessageMapper;
import com.sweetcircle.mapper.UserInfoMapper;
import com.sweetcircle.service.ChatMessageService;
import com.sweetcircle.utils.AnanUtils;
import com.sweetcircle.websocket.MessageHandler;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.List;


/**
 * 聊天消息表 业务接口实现
 */
@Service("chatMessageService")
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessage> implements ChatMessageService {

    @Resource
    private MessageHandler messageHandler;

    @Resource
    private ChatMessageMapper chatMessageMapper;




    @Override
    public MessageSendDto saveMessage(ChatMessage chatMessage, TokenUserInfoDto tokenUserInfoDto) {

        MessageSendDto messageSendDto = AnanUtils.copyBean(chatMessage, MessageSendDto.class);

        // todo 对消息进行保存


        messageHandler.sendMessage(messageSendDto);
        // todo 修改保存消息的状态
        return messageSendDto;
    }

    @Override
    public void saveMessageFile(String userId, Long messageId, MultipartFile file, MultipartFile cover) {

    }

    @Override
    public File downloadFile(TokenUserInfoDto userInfoDto, Long messageId, Boolean cover) {
        return null;
    }
}
